const generateId = () => {
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) + '-' + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
}
const generateRelation = ({ links = [], nodes = [] }) => {
  for (let i = 0; i < nodes.length; i++) {
    const { id } = nodes[i]
    nodes[i].role_id = id
    for (let n = 0; n < links.length; n++) {
      const { from, to } = links[n]
      if (from === id) {
        links[n].source = i
      }
      if (to === id) {
        links[n].target = i
      }
    }
  }
  return { links, nodes }
}
export { generateRelation, generateId }
